package com.xcx.robot.mirai.key;

import com.xcx.robot.util.FreemarkerUtils;
import lombok.Getter;
import lombok.SneakyThrows;

import javax.imageio.ImageIO;
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: 邢晨旭
 * @Date: 2021/5/26 16:10
 * @Description:
 */
@Getter
public enum KeyWord {
    //    TEST(3, 1,false, "测试专用！",""),
    MENU(2, 1, false, "功能菜单", "调出此表格"),
    VOICE(3, 2, false, "语音测试", "语音测试 想要让兔砸说的话"),
    GOLD(3, 3, false, "金价", "金价 区服(区服可为空,默认剑胆琴心)"),
    MUSIC(3, 2, false, "搜歌", "搜歌 歌名"),
    IMAGE(2, 1, false, "美女", ""),
    MAGNETIC(2, 2, false, "车牌", ""),
    RECALL(2, 3, false, "撤回", "撤回 序号/默认1(暂时没啥用，不完整)"),
    MACRO(3, 2, false, "宏", "宏 心法"),
    DAILY(3, 1, false, "日常", "日常"),
    ANNOUNCE(3, 1, false, "更新公告", "更新公告"),
    FLOWER(3, 2, false, "花价", "花价 花名 地图(地图可空,默认全部地图查询)"),
    SAO_TALK(3, 1, false, "骚话", "骚话"),
    FLATTERER(3, 1, false, "舔狗日记", "舔狗日记"),
    SERENDIPITY(3, 2, false, "条件", "条件 奇遇名称"),
//    SERENDIPITY_S(3, 2,false, "奇遇",""),
//    PRICE(3, 2,false, "物价",""),
//    TEAM(1, 1,false, "查看团队",""),
//    CREATE_TEAM(2, 2,false, "开团",""),
//    CANCEL_TEAM(2, 1,false, "取消开团",""),
//    TEAM_NUMBER(1, 1,false, "团队人数",""),
//    SIGN_UP(1, 2,false, "报名",""),

    ;


    /**
     * 1私聊 2群聊 3通用
     */
    public Integer type;
    /**
     * 关键码 1、单词命令 2、组合命令,3不限
     */
    public Integer code;
    /**
     * 是否有CD
     */
    public Boolean CD;
    /**
     * 关键词
     */
    public String keyWord;

    public String des;

    KeyWord(Integer type, Integer code, Boolean cd, String keyWord, String des) {
        this.type = type;
        this.code = code;
        this.CD = cd;
        this.keyWord = keyWord;
        this.des = des;
    }

    public static KeyWord groupFind(String keyWord) {
        List<KeyWord> collect = Arrays.stream(KeyWord.values()).filter(e -> e.type > 1).collect(Collectors.toList());
        for (KeyWord value : collect) {
            if (keyWord.equals(value.keyWord)) {
                return value;
            }
        }
        return null;
    }

    @SneakyThrows
    public static void menu() {
//        List<KeyWord> collect = Arrays.stream(KeyWord.values()).filter(e -> e.type > 1).sorted(Comparator.comparing(KeyWord::getCode).reversed()).collect(Collectors.toList());
        List<KeyWord> collect = Arrays.stream(KeyWord.values()).filter(e -> e.type > 1).sorted(Comparator.comparing(KeyWord::getCode)).collect(Collectors.toList());
        Map<String, Object> result = new HashMap<>();
        result.put("list", collect);
        ImageIO.write(Objects.requireNonNull(FreemarkerUtils.turnImage("menu.ftl", result)), "png", new File("menu.png"));
    }

}
